Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ignore empty env vars #198

Merged
merged 7 commits into from
Dec 11, 2023

Conversation

niventc
Copy link
Contributor

@niventc niventc commented Dec 4, 2023

As suggested at pydantic/pydantic#3796, we often have environment variables set but empty, and would prefer to use the default value for the field instead of raising an exception.

This adds the ability to ignore empty environment variables by setting env_ignore_empty=True, e.g.

os.environ['app_a'] = ''

class Settings(BaseSettings):
        a: str = 'default'

        model_config = SettingsConfigDict(env_prefix="app_", env_ignore_empty=True)

assert Settings().a == 'default'

@niventc niventc changed the title Feat ignore empty env vars feat: ignore empty env vars Dec 4, 2023
Copy link

codecov bot commented Dec 4, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (1d6950f) 97.45% compared to head (2cf04fb) 97.47%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #198      +/-   ##
==========================================
+ Coverage   97.45%   97.47%   +0.02%     
==========================================
  Files           5        5              
  Lines         314      317       +3     
  Branches       69       66       -3     
==========================================
+ Hits          306      309       +3     
  Misses          6        6              
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hramezani hramezani merged commit 4f24fad into pydantic:main Dec 11, 2023
20 checks passed
@hramezani
Copy link
Member

Thanks @niventc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants